package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 档案接收类型
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum ArchiveSaveEnum {
  /** 出库 */
  OUT_OF_WAREHOUSE(1, "出库"),
  STORAGE(2, "入库"),
  ADD_ENTITY(3, "增加实体"),
  DEFECT_REGISTRATION(4, "缺损登记"),
  OFFLINE_STORAGE(5, "离线存储"),
  HANDOVER(6, "移交进馆"),
  ;

  private Integer code;
  private String desc;

  public static ArchiveSaveEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  @JsonCreator
  public static ArchiveSaveEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
